<?php
	require_once 'BaseController.php';

	class Admin_InterfaceController extends BaseController {
		public function indexAction(){
			echo $this->view->render("interface/index.htm");
			exit;
		}
		
		//navigation
		public function navigationAction(){
			$navigationDAO = $this->orm->createDAO("_wenda_navigation");
			$navigationDAO ->selectLimit .= " and nav_type = 1 order by nav_order asc";
			$rslist = $navigationDAO ->get();
			
			$this->view->assign("rslist",$rslist);
			echo $this->view->render("interface/navigation.htm");
			exit;
		}
		
		//footer navigation
		public function footernavigationAction(){
			$navigationDAO = $this->orm->createDAO("_wenda_navigation");
			$navigationDAO ->selectLimit .= " and nav_type = 2 order by id asc";
			$rslist = $navigationDAO ->get();
			
			$this->view->assign("rslist",$rslist);
			echo $this->view->render("interface/footernavigation.htm");
			exit;
		}
		
		//add navigation
		public function addNavigationAction(){
			$name = HttpUtil::postString("nav_name");
			$url = HttpUtil::postString("nav_url");
			$type = HttpUtil::postString("nav_type");
			if($name != "" && $url != ""){
				$navigationDAO = $this->orm->createDAO("_wenda_navigation");
				$navigationDAO ->nav_type = $type;
				$navigationDAO ->nav_name = $name;
				$navigationDAO ->nav_url = $url;
				$navigationDAO ->nav_img = HttpUtil::postString("navigation_img");
				$navigationDAO ->nav_target = HttpUtil::postString("nav_target");
				$navigationDAO ->nav_order = HttpUtil::postString("nav_order");
				$navigationDAO ->save();
				
				if($type == 1){
					echo '<script type="text/javascript">parent.location.href = "/admin/interface/navigation";</script>';
				}elseif($type == 2) {
					echo '<script type="text/javascript">parent.location.href = "/admin/interface/footernavigation";</script>';
				}
				exit;
			}else {
				$this->alert_back("标题和url不能为空");
			}
		}
		
		//del navigation
		public function delNavigationAction(){
			$id = $this->_getParam("id");
			$type = $this->_getParam("type");
			if($id != ""){
				$navigationDAO = $this->orm->createDAO("_wenda_navigation");
				$navigationDAO ->findId($id);
				$navigationDAO ->delete();
				
				if($type == 1){
					$this->alert_go("删除成功", "/admin/interface/navigation");
				}elseif($type == 2) {
					$this->alert_go("删除成功", "/admin/interface/footernavigation");
				}
				
			}else {
				$this->alert_back("您的操作有误");
			}
		}
	}
	